package com.itheima.cases;

import java.util.Random;
import java.util.Scanner;

public class TextDemo10 {
    public static void main(String[] args) {
        int[] random = randomNumber();
        int[] useruser = userNumbers();
        System.out.println("您投注的号码为：");
        printnumber(useruser);
        System.out.println("开奖的号码为：");
        printnumber(random);
        countnumber(random, useruser);
    }

    //打印号码
    private static void printnumber(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            System.out.print((i == arr.length - 1) ? arr[i] : arr[i] + ",");
        }
        System.out.println("]");
    }

    //生成号码
    public static int[] randomNumber() {
        Random ra = new Random();
        int[] randomNumbers = new int[7];
        for (int i = 0; i < randomNumbers.length - 1; i++) {
            while (true) {
                int number = ra.nextInt(33) + 1;
                if (!pd(randomNumbers, number)) {
                    randomNumbers[i] = number;
                    break;
                }
            }
        }
        randomNumbers[randomNumbers.length - 1] = ra.nextInt(16) + 1;
        ;
        return randomNumbers;
    }

    //用户输入号码
    public static int[] userNumbers() {
        Scanner rs = new Scanner(System.in);
        Random ra = new Random();
        int[] numbers = new int[7];
        for (int i = 0; i < numbers.length - 1; i++) {
            while (true) {
                System.out.println("请您输入第" + (i + 1) + "个【红球】号码（1-33）：");
                int insert = rs.nextInt();
                if (insert < 1 || insert > 33) {
                    System.out.println("【红球】只能输入1-33之间的号码！！！");
                } else {
                    if (pd(numbers, insert)) {
                        System.out.println("不能输入重复的数字,请重新输入号码！！！");
                    } else {
                        numbers[i] = insert;
                        break;
                    }
                }
            }
        }
        while (true) {
            System.out.println("请您输入一个【蓝球】号码（1-16）：");
            int insert = rs.nextInt();
            if (insert < 1 || insert > 16) {
                System.out.println("【蓝球】只能输入1-16之间的号码！！！");
            } else {
                numbers[numbers.length - 1] = insert;
                break;
            }
        }
        return numbers;
    }

    //判断输入的内容是否重复
    private static boolean pd(int[] numbers, int insert) {
        for (int i = 0; i < numbers.length - 1; i++) {
            if (numbers[i] == insert) {
                return true;
            }
        }
        return false;
    }

    //号码开奖
    public static void countnumber(int[] randomarr, int[] userarr) {
        int redcount = 0;
        int bluecount = 0;
        for (int i = 0; i < userarr.length - 1; i++) {
            if (pd(randomarr, userarr[i])) {
                redcount++;
            }
        }
        bluecount = randomarr[randomarr.length - 1] == userarr[userarr.length - 1] ? 1 : 0;
        System.out.println("您命中的红球数量为：" + redcount);
        System.out.println("您命中的蓝球数量为：" + bluecount);
        if (redcount == 6 && bluecount == 1) {
            System.out.println("恭喜您，中了【一等奖】，获得了【1000万】元奖金！！！");
        } else if (redcount == 6 && bluecount == 0) {
            System.out.println("恭喜您，中了【二等奖】，获得了【500万】元奖金！！！");
        } else if (redcount == 5 && bluecount == 1 || redcount == 5 && bluecount == 0) {
            System.out.println("恭喜您，中了【三等奖】，获得了【3000】元奖金！！！");
        } else if (redcount == 5 && bluecount == 0 || redcount == 4 && bluecount == 1) {
            System.out.println("恭喜您，中了【四等奖】，获得了【200】元奖金！！！");
        } else if (redcount == 4 && bluecount == 0 || redcount == 3 && bluecount == 1) {
            System.out.println("恭喜您，中了【五等奖】，获得了【10】元奖金！！！");
        } else if (redcount < 3 && bluecount == 1) {
            System.out.println("恭喜您，中了【六等奖】，获得了【5】元奖金！！！");
        } else {
            System.out.println("很遗憾，您与奖金擦肩而过，感谢您的惠顾！！！");
        }
    }
}